//
//  VisitorView.swift
//  WeiBo
//
//  Created by 佘红响 on 15/11/7.
//  Copyright © 2015年 she. All rights reserved.
//

import UIKit

class VisitorView: UIView {
    
    /// 可以旋转的转盘
    @IBOutlet weak var rotationImageView: UIImageView!
    /// 显示的大图
    @IBOutlet weak var iconImageView: UIImageView!
    /// 显示的title
    @IBOutlet weak var titleLabel: UILabel!
    
    /**
    设置数据
    
    :param: imageName "大图"的图片名
    :param: title     显示在titleLabel上的文字
    */
    func setupInfo(imageName: String?, title: String) {
        
        // 如果,iamgeName为空的话,代表是首页,则开始动画并直接返回
        guard let name = imageName else {
            startAnimation()
            return
        }
        
        rotationImageView.hidden = true
        iconImageView.image = UIImage(named: name)
        titleLabel.text = title
        
    }
    
    /**
    快速创建VisitorView对象
    */
    class func createVisitorView() -> VisitorView {
        return NSBundle.mainBundle().loadNibNamed("VisitorView", owner: nil, options: nil).last as! VisitorView
    }
    
    /**
    转盘旋转的动画
    */
    private func startAnimation() {
        
        let animation = CABasicAnimation(keyPath: "transform.rotation")
        
        animation.toValue = 2 * M_PI
        animation.repeatCount = MAXFLOAT
        animation.duration = 10
        
        // 告诉系统不要随便给我移除动画, 只有当控件销毁的时候才需要移除
        animation.removedOnCompletion = false
        
        rotationImageView.layer.addAnimation(animation, forKey: nil)
        
    }
    
    /**
    注册
    
    :param: sender 注册按钮
    */
    @IBAction func regist(sender: UIButton) {
    }
    
    /**
    登录
    
    :param: sender 登录
    */
    @IBAction func login(sender: UIButton) {
        
    }
    
}
